import java.util.*;
/**
 * 在这里给出对类 Player 的描述。
 * 
 * @作者（你的名字）
 * @版本（一个版本号或者一个日期）
 */
public class Player
{
    private int energy;
    private Map<String,Thing> bag= new HashMap<>();
    private boolean specialItem = false;
    
    public Player(){
        energy=100;
    }
    
    public void walk(){
        energy -= 10;
        printEnergy();
    }
    
    public void pick(Thing thing) {
        bag.put(thing.getName(), thing);
    }
    
    public boolean isAlive(){
        return energy > 0;
    }
    
    public boolean isDead(){
        return energy <=0;
    }
    
    public void hurt(int damage){
        energy -= damage;
        if (isDead()){
            System.out.println("你被怪物给杀死了，你没有成功找到真相！游戏结束！");
        }
    }
    
    public void addToBag(Thing thing) {
        if (thing == null) {
            System.out.println("没东西可以捡!");
        }
        else {
            pick(thing);
            System.out.println( thing.getName() +"成功加入背包!");
            if(thing.getName()=="装着证据的U盘")
                this.specialItem=true;
        }
    }
    
    public void CheckBag(){
        if(bag.isEmpty()){
            System.out.println("你的背包中没有任何东西！");
        }
        else {
            System.out.println("你的背包有如下的东西:");
            for(String key : bag.keySet()){
                System.out.println("名称:  "+bag.get(key).getName()+ "   回复能量" + bag.get(key).getEnergy() + "点");
            }
        }
    }

    public void eat(String name){
        Thing thing = bag.get(name);
        if(thing != null){
            energy += thing.getEnergy();
        }
    }
    
    public void eatThing(Command command){
        if(!command.hasSecondWord()) {
            System.out.println("Eat what?");
            return;
        }
        String key = command.getSecondWord();
        if (bag.containsKey(key)) {
            eat(key);
            System.out.println("你的能量回复了" + bag.get(key).getEnergy()+"点!");
            System.out.println("你当前的能量是" + energy + "点!");
        }
        else {
            System.out.println("抱歉! 使用前请查看背包中是否存在该物件!");
            System.out.println("你可以通过'check'命令来查看背包中的物品!");
        }
        bag.remove(key);
    }
    
    public boolean getSpecialItem(){
        return this.specialItem;
    }
    
    private void printEnergy(){
        System.out.println("移动消耗了5点体力,玩家当前体力为：" + this.energy);
    }
}
